package com.neuronbit.businessflow.intellij.editor;

import com.intellij.designer.LightToolWindowContent;
import com.intellij.openapi.project.Project;
import com.neuronbit.businessflow.intellij.editor.swing.GuiEditor;
import com.neuronbit.businessflow.intellij.editor.swing.editor.propertyInspector.PropertyInspector;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * The type Designer tool window.
 */
public class DesignerToolWindow  implements LightToolWindowContent {
    private final JPanel propertyPane;
    private final Project project;

    /**
     * Instantiates a new Designer tool window.
     *
     * @param project  the project
     * @param designer the designer
     */
    public DesignerToolWindow(@NotNull Project project, GuiEditor designer) {
        this.project = project;
        propertyPane = new JPanel();//new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
        propertyPane.setLayout(new BorderLayout());
        propertyPane.setMinimumSize(new Dimension(320, -1));

        final PropertyInspector inspector = new PropertyInspector(this.project, designer.getGraphComponent());
        propertyPane.add(inspector, BorderLayout.CENTER);

        designer.getGraphComponent().getGraphControl().addMouseListener(new MouseAdapter() {
            @Override
            public void mouseReleased(MouseEvent e) {
//                Object cell = graphComponent.getCellAt(e.getX(), e.getY());
//                if (null != cell) {
//                    graphComponent.setSelection(((mxCell) cell).getId());
//                } else {
//                    graphComponent.setSelection(((mxCell)graphComponent.getGraph().getModel().getRoot()).getId());
//                }
                inspector.synchWithTree(true);
            }
        });
        inspector.setEditor(designer);
    }

    @Override
    public void dispose() {

    }

    /**
     * Gets tool window panel.
     *
     * @return the tool window panel
     */
    public JComponent getToolWindowPanel() {
        return propertyPane;
    }

    /**
     * Update.
     *
     * @param designer the designer
     */
    public void update(GuiEditor designer) {

    }
}
